<?php

use Illuminate\Http\Request;
use Illuminate\Support\Facades\Auth;

/*
|--------------------------------------------------------------------------
| API Routes
|--------------------------------------------------------------------------
|
| Here is where you can register API routes for your application. These
| routes are loaded by the RouteServiceProvider within a group which
| is assigned the "api" middleware group. Enjoy building your API!
|
*/

Route::middleware(['auth:api','before'])->group(function(){
    Route::get('/user',function (Request $request){
        if (!Auth::guard('api')->check()) {
            return ['code' => 401, 'msg' => '请先登录！'];// 中断请求返回登录错误
        }else{
            $user_info = Auth::guard('api')->user();
            return ['code' => 0, 'msg' => 'ok', 'data' => array('user_info' => $user_info)];
        }
    });
});


// 公共请求
Route::namespace('Common')->prefix('common')->group(function(){
    Route::namespace('Amap')->prefix('amap')->group(function(){
        Route::any('regeo','GeocodeRegeoController@index');//逆地址编码
    });
    Route::any('upload','UploadController@index');//上传文件
    Route::any('jsapi','JsApiController@index');//jsapi
    Route::any('enums','EnumsController@index');//通用枚举查询接口
    Route::any('address','AddressController@index');//地址查询接口
    Route::any('log','AddLogController@index');//通用日志记录接口
    Route::any('images','ImagesController@index');// 通用oss图片链接
});


/**
 * client:微信网页
 */
Route::namespace('Client')->prefix('client')->group(function(){
    Route::namespace('Auth')->prefix('auth')->group(function(){
        Route::post('token','AuthAccessTokenController@index'); //来飞网获取access_token
    });
    /**
     * 中间件：微信认证，查询用户信息
     */
    Route::middleware('client')->group(function(){
        /**
         * 霸王餐抽奖活动
         */
        Route::namespace('Activity')->prefix('activity')->group(function(){
            /**
             * 商家
             */
            Route::namespace('Shop')->prefix('shop')->group(function(){

            });
            /**
             * 达人
             */
            Route::namespace('Talent')->prefix('talent')->group(function(){
                Route::post('list','ActivityListController@index');//正在进行的霸王餐活动列表
                Route::post('list/before','ActivityListBeforeController@index');//查询霸王餐活动列表前对用户信息的审查
                Route::post('history','ActivityTalentHistoryController@index');// 我的参与记录
                Route::post('detail','ActivityDetailController@index');//霸王餐活动详情
                Route::post('confirm','WinnerConfirmController@index');//领取霸王餐
                Route::post('confirm/before','WinnerConfirmBeforeController@index');//领取霸王餐前的查询
                Route::post('consume/before','WinnerConsumeBeforeController@index');//消费霸王餐的信息
            });
            Route::post('create/before','ActivityCreateBeforeController@index');// 发布霸王餐前的信息查询
            Route::post('create','ActivityCreateController@index');//发布霸王餐
            Route::post('participate/record','ActivityParticipateRecordController@index'); // 霸王餐活动参与记录
            Route::post('buy/before','LotteryBuyBeforeController@index');//购买霸王餐前的验证和查询价格
            Route::post('buy','LotteryBuyController@index');//购买霸王餐生成订单
            Route::post('lottery/detail','LotteryDetailController@index');//霸王餐活动详情
            Route::post('lottery/participate','LotteryParticipateController@index');//参与霸王餐活动
            Route::post('lottery/consume','LotteryConsumeController@index');//霸王餐核销
        });
        Route::namespace('Course')->prefix('course')->group(function(){
            Route::post('buy/before','CourseBuyBeforeController@index');//课程预览（计算购买价格）
            Route::post('store','CourseStoreController@index');//课程列表
            Route::post('detail','CourseDetailController@index');//课程详情
            Route::post('detail/lesson','LessonDetailController@index');//(单节)课程详情
            Route::post('vip','CourseVipController@index');//会员详情
            Route::post('vip/load','CourseLoadVipController@index');//会员购买（续费）前的价格查询
            Route::post('pay','CoursePayController@index');//创建订单
        });
        Route::namespace('Common')->prefix('common')->group(function(){
            Route::post('message/send','SendMessageController@index');//发送短信
            Route::post('message/check','CheckMessageController@index');//验证手机号验证码，绑定手机号
            Route::post('history/explore','HistoryExploreController@index');//（商家）探店记录
            Route::post('history/explore/before','HistoryExploreBeforeController@index');//（商家）所有店铺
            Route::post('history/lottery','HistoryLotteryController@index');//（商家）霸王餐记录
            Route::post('history/lottery/before','HistoryLotteryBeforeController@index');// (商家)发布过霸王餐的店铺活动信息
            Route::post('subscribe/code','SubscribeCodeController@index');// 关注专属二维码
        });
        Route::namespace('Mine')->prefix('mine')->group(function(){
            Route::post('mine','MineController@index');//我的个人中心
        });
        Route::namespace('Shop')->prefix('shop')->group(function(){// 店铺操作
            Route::post('store','ShopStoreController@index');//查询店铺信息
            Route::post('bind','ShopBindController@index');//绑定店铺
            Route::namespace('Explore')->prefix('explore')->group(function(){
                Route::post('buy','ExploreBuyController@index');//购买探店
                Route::post('buy/list','ExploreBuyListController@index');//购买探店前的验证
                Route::post('apply','ExploreApplyController@index');//申请使用探店
//                Route::post('republish','ExploreRepublishController@index');// todo 过期订单重新发布(功能设计不完整，暂不启用)
                Route::post('channel','ExploreChannelsController@index');// 查询探店渠道及余量
                Route::post('invite','ExploreInviteController@index');//抢单页内容
                Route::post('task','ExploreTaskController@index');// 抢单(挂起订单)
                Route::post('task/detail','ExploreTaskDetailController@index');//挂起订单验证信息
                Route::post('accept','ExploreAcceptController@index');//接单(生成工单)
                Route::post('list','ExploreListController@index');//待抢单列表
                Route::post('list/before','ExploreListBeforeController@index');//抢单前的检查
                Route::post('cancel','ExploreOrderCancelController@index');//店主关闭订单
                Route::post('confirm','ExploreConfirmController@index');//店主验收
                Route::post('appeal','ExploreAppealController@index');//达人申诉
                Route::post('give_up','ExploreGiveUpController@index');//达人放弃工单
                Route::post('refund','ExploreRefundController@index');//店主申请退款
            });
            Route::namespace('Goods')->prefix('goods')->group(function(){
                Route::post('list','GoodsListController@index');//查询霸王餐活动策略
                Route::post('detail','GoodsDetailController@index');//霸王餐活动策略详情
                Route::post('create','GoodsCreateController@index');//新建霸王餐活动策略
            });
        });
        Route::namespace('Talent')->prefix('talent')->group(function(){ //达人操作
            Route::post('list','TalentListController@index');// 我的认证
            Route::post('apply','TalentApplyController@index');//达人认证
            Route::post('apply/before','TalentApplyBeforeController@index');//查询未注册的渠道
            Route::post('history/received','TalentHistoryReceivedController@index');//我的探店
            Route::post('history/log','TalentHistoryReceivedController@log');//探店日志
            Route::post('history','TalentHistoryController@index');//我的探店
            Route::post('upload','TalentUploadController@index');//上传投稿
            Route::post('notice','TalentNoticeController@index');//用户切换是否接受发单微信消息推送
        });
    });
});

// 测试环境接口
Route::namespace('Testing')->prefix('testing')->group(function(){
    Route::middleware('testing')->group(function(){
        Route::any('add/user','LotteryAddUsersController@index');// 添加用户
        Route::any('participate','LotteryParticipateController@index');// 参与活动
    });
});


/**
 * cms管理系统，需要auth认证
 */
Route::middleware('auth:api')->group(function(){
    Route::namespace('Activity')->prefix('activity')->group(function(){
        Route::prefix('goods')->group(function(){
            Route::post('store','GoodsStoreController@index');//查询商品
            Route::post('status','GoodsStatusChangeController@index');//修改商品状态
        });
        Route::prefix('activity')->group(function(){
            Route::post('store','ActivityStoreController@index');//查询活动
            Route::post('detail','ActivityDetailController@index');//查询活动详情
            Route::post('status','ActivityStatusChangeController@index');//修改活动状态
            Route::post('consume','ActivityConsumeController@index');//管理员核销
            Route::post('cancel','ActivityCancelController@index');//管理员关闭霸王餐活动
        });
    });
    Route::namespace('Laifei')->prefix('laifei')->group(function(){
        Route::namespace('Explore')->prefix('explore')->group(function(){
            Route::post('store','LaifeiExploreStoreController@index');//订单列表
            Route::post('detail','LaifeiExploreDetailController@index');//订单详情
        });
        Route::namespace('Orders')->prefix('orders')->group(function(){
            Route::post('store','LaifeiOrdersStoreController@index');//查询订单
            Route::post('detail','LaifeiOrderDetailController@index');//订单详情
        });
        Route::namespace('Settlement')->prefix('settlement')->group(function(){
            Route::post('course','SettlementCourseController@index');//课程结算
            Route::post('explore','SettlementExploreController@index');//探店结算
            Route::post('vip','SettlementVipController@index');//黑卡会员结算
            Route::any('export','SettlementExportController@index');//黑卡会员结算
            Route::post('proxy','ProxyStoreController@index');//代理查询
            Route::post('proxy/detail','ProxyDetailController@index');//代理详情查询
            Route::post('proxy/log','ProxyDetailController@log');//代理详情流水查询
        });
        Route::namespace('Shop')->prefix('shop')->group(function(){
            Route::post('store','ShopStoreController@index');//查询店铺
            Route::post('detail','ShopDetailController@index');//店铺详情
            Route::post('verify','ShopVerifyController@index');// 店铺审核
        });
        Route::namespace('Shopkeeper')->prefix('shopkeeper')->group(function(){
            Route::post('store', 'ShopkeeperStoreController@index');//查询店主
            Route::post('detail','ShopkeeperDetailController@index');// 店主详情
        });
        Route::namespace('Talent')->prefix('talent')->group(function(){
            Route::post('store','LaifeiTalentStoreController@index');//达人列表
            Route::post('detail','LaifeiTalentDetailController@index');//达人详情
            Route::post('auth','LaifeiTalentAuthController@index');//达人认证
        });
        Route::namespace('Vip')->prefix('vip')->group(function(){
            Route::post('store','LaifeiVipStoreController@index');//会员列表
            Route::post('detail','LaifeiVipDetailController@index');//会员详情
        });
        Route::namespace('Work')->prefix('work')->group(function(){
            Route::post('store','LaifeiWorkStoreController@index');//工单列表
            Route::post('detail','LaifeiWorkDetailController@index');//工单详情
            Route::post('accept','LaifeiWorkAcceptController@index');//工单验收/拒回
            Route::post('settlement','LaifeiWorkSettlementController@index');//工单结算
            Route::post('settlement/resend','LaifeiWorkReSettlementController@index');//红包补发
            Route::post('cancel','LaifeiWorkCancelController@index');//工单手动关闭
            Route::post('hangup','LaifeiWorkHangUpController@index');//查询申诉工单
            Route::post('feedback','LaifeiWorkFeedbackController@index');// 审核工单
        });
    });

    Route::namespace('Mine')->prefix('mine')->group(function(){
        Route::post('mine','MineController@index');//个人中心
        Route::post('reset_password','ResetPasswordController@index');//修改密码
    });

    Route::namespace('Setting')->prefix('setting')->group(function(){
        Route::namespace('Template')->prefix('template')->group(function(){
            Route::post('store','TemplateStoreController@index');// 查询模板消息推送历史记录
            Route::post('send','TemplateSendController@index');// 发送模板消息
            Route::any('data','TemplateDataController@index');// 模板消息信息
        });
    });
});

Route::namespace('Wechat')->prefix('wechat')->group(function(){
    Route::post('test','WechatTestController@index');
    Route::any('pay/success','WechatPaySuccessController@index');// 支付成功通知接口
    Route::any('refund/success','WechatRefundSuccessController@index');// 退款成功通知接口
});
